<?php require_once('../Connections/miportal.php'); 
mysql_query("SET NAMES 'utf8'");?>
<?php
//initialize the session
if (!isset($_SESSION)) {
  session_start();
}

// ** Logout the current user. **
$logoutAction = $_SERVER['PHP_SELF']."?doLogout=true";
if ((isset($_SERVER['QUERY_STRING'])) && ($_SERVER['QUERY_STRING'] != "")){
  $logoutAction .="&". htmlentities($_SERVER['QUERY_STRING']);
}

if ((isset($_GET['doLogout'])) &&($_GET['doLogout']=="true")){
  //to fully log out a visitor we need to clear the session varialbles
  $_SESSION['MM_Username'] = NULL;
  $_SESSION['MM_UserGroup'] = NULL;
  $_SESSION['PrevUrl'] = NULL;
  unset($_SESSION['MM_Username']);
  unset($_SESSION['MM_UserGroup']);
  unset($_SESSION['PrevUrl']);
	
  $logoutGoTo = "../private/login.php";
  if ($logoutGoTo) {
    header("Location: $logoutGoTo");
    exit;
  }
}
?>
<?php
if (!isset($_SESSION)) {
  session_start();
}
$MM_authorizedUsers = "";
$MM_donotCheckaccess = "true";

// *** Restrict Access To Page: Grant or deny access to this page
function isAuthorized($strUsers, $strGroups, $UserName, $UserGroup) { 
  // For security, start by assuming the visitor is NOT authorized. 
  $isValid = False; 

  // When a visitor has logged into this site, the Session variable MM_Username set equal to their username. 
  // Therefore, we know that a user is NOT logged in if that Session variable is blank. 
  if (!empty($UserName)) { 
    // Besides being logged in, you may restrict access to only certain users based on an ID established when they login. 
    // Parse the strings into arrays. 
    $arrUsers = Explode(",", $strUsers); 
    $arrGroups = Explode(",", $strGroups); 
    if (in_array($UserName, $arrUsers)) { 
      $isValid = true; 
    } 
    // Or, you may restrict access to only certain users based on their username. 
    if (in_array($UserGroup, $arrGroups)) { 
      $isValid = true; 
    } 
    if (($strUsers == "") && true) { 
      $isValid = true; 
    } 
  } 
  return $isValid; 
}

$MM_restrictGoTo = "../private/login.php";
if (!((isset($_SESSION['MM_Username'])) && (isAuthorized("",$MM_authorizedUsers, $_SESSION['MM_Username'], $_SESSION['MM_UserGroup'])))) {   
  $MM_qsChar = "?";
  $MM_referrer = $_SERVER['PHP_SELF'];
  if (strpos($MM_restrictGoTo, "?")) $MM_qsChar = "&";
  if (isset($_SERVER['QUERY_STRING']) && strlen($_SERVER['QUERY_STRING']) > 0) 
  $MM_referrer .= "?" . $_SERVER['QUERY_STRING'];
  $MM_restrictGoTo = $MM_restrictGoTo. $MM_qsChar . "accesscheck=" . urlencode($MM_referrer);
  header("Location: ". $MM_restrictGoTo); 
  exit;
}
?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  if (PHP_VERSION < 6) {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}

$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
  $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "formRegCandidato")) {
	$ins_candidato=base64_decode($_POST['ins_candidato']);
	if($_SESSION['MM_tp_programa']=="MI PRIMERA EMPRESA"){
	$query_insert_obj="INSERT INTO cor_ben_ies_primaria (id_cor_ies_primaria, id_cor_candidato) VALUES (%s, %s)";
	}
	else{
		$query_insert_obj="INSERT INTO cor_ben_ies_emp (id_cor_ies_empresa, id_cor_candidato) VALUES (%s, %s)";
	}
  $insertSQL = sprintf($query_insert_obj,
                       GetSQLValueString($_POST['ins_ies_empresa'], "int"),
                       GetSQLValueString($ins_candidato, "int"));

  mysql_select_db($database_miportal, $miportal);
  $Result1 = mysql_query($insertSQL, $miportal) or die(mysql_error());
  $update_status_registro= sprintf("UPDATE cor_candidato SET tp_stat_registro=4 WHERE id_cor_candidato=%s",
  		GetSQLValueString($ins_candidato, "int"));
  $Result2 = mysql_query($update_status_registro, $miportal) or die(mysql_error());

  $insertGoTo = "../report/report_rov_candidatos.php";
  if (isset($_SERVER['QUERY_STRING'])) {
    $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
    $insertGoTo .= $_SERVER['QUERY_STRING'];
  }
  header(sprintf("Location: %s", $insertGoTo));
}

$ies_rs_ies_empresa = "-1";
if (isset($_SESSION['MM_id_target'])) {
  $ies_rs_ies_empresa = $_SESSION['MM_id_target'];
}
$folio_rs_Obj = "-1";
if (isset($_GET['folio_empresa'])) {
  $folio_rs_Obj = base64_decode($_GET['folio_empresa']);
}else if (isset($_GET['folio_primaria'])) {
  $folio_rs_Obj = base64_decode($_GET['folio_primaria']);
}
$convocatoria_rs_ies_empresa = "-1";
if (isset($_SESSION['MM_id_cat_convocatoria'])) {
  $convocatoria_rs_ies_empresa = $_SESSION['MM_id_cat_convocatoria'];
}
if($_SESSION['MM_tp_programa']=="MI PRIMERA EMPRESA"){
	$query_rs_obj="SELECT id_cor_ies_primaria AS id FROM cor_ies_primaria WHERE id_cat_ies = %s AND id_cat_primaria=%s AND id_cat_convocatoria=%s";
}
else{
	$query_rs_obj="SELECT id_cor_ies_empresa AS id FROM cor_ies_empresa WHERE id_cat_ies = %s AND cor_ies_empresa.id_cat_empresa=%s AND cor_ies_empresa.id_cat_convocatoria=%s";
}
mysql_select_db($database_miportal, $miportal);
$query_rs_ies_empresa = sprintf($query_rs_obj, 
										GetSQLValueString($ies_rs_ies_empresa, "int"),
										GetSQLValueString($folio_rs_Obj, "int"),
										GetSQLValueString($convocatoria_rs_ies_empresa, "int"));
$rs_ies_empresa = mysql_query($query_rs_ies_empresa, $miportal) or die(mysql_error());
$row_rs_ies_empresa = mysql_fetch_row($rs_ies_empresa);
$totalRows_rs_ies_empresa = mysql_num_rows($rs_ies_empresa);

if($totalRows_rs_ies_empresa==0 && $_SESSION['MM_tp_programa']!="MI PRIMERA EMPRESA"){
 //REALIZAMOS RELACIÓN EMPRESA IES
  
    $insert_ies_empresa= sprintf("INSERT INTO cor_ies_empresa (id_cat_convocatoria, id_cat_programa, id_cat_ies, id_cat_empresa) 
	VALUES 	(%s, %s, %s, %s)",
                       GetSQLValueString($_SESSION['MM_id_cat_convocatoria'], "text"),
					   GetSQLValueString($_SESSION['MM_tp_programa'], "text"),
					   GetSQLValueString($_SESSION['MM_id_target'], "text"),
					   GetSQLValueString($folio_rs_Obj, "int"));
   mysql_select_db($database_miportal, $miportal);
  $Result1 = mysql_query($insert_ies_empresa, $miportal) or die(mysql_error());
    //FIN INSERT EMPRESA IES	
	//Realizamos nuevamente el select a la base de datos
	$rs_ies_empresa = mysql_query($query_rs_ies_empresa, $miportal) or die(mysql_error());
	$row_rs_ies_empresa = mysql_fetch_row($rs_ies_empresa);
	$totalRows_rs_ies_empresa = mysql_num_rows($rs_ies_empresa);

}




?>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximun-scale=1">
<title>FUNDACIÓN EDUCACIÓN SUPERIOR-EMPRESA</title>
<!--Hoja de estilo principal-->
<link href="../css/styletd2.css" rel="stylesheet" type="text/css">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<link rel="shortcut icon" href="stylesheet/img/devil-icon.png"> 
<link rel="stylesheet" type="text/css" href="../css/mos-style.css">
<link rel="stylesheet" type="text/css" href="../css/menu.css"><!--Pemanggilan gambar favicon-->
 <!--pemanggilan file css-->
<script src="../SpryAssets/SpryValidationTextField.js" type="text/javascript"></script>
<link href="../SpryAssets/SpryValidationTextField.css" rel="stylesheet" type="text/css">
<script language=""="JavaScript">
	function conMayusculas(field) {
				field.value = field.value.toUpperCase()
		}
			function incubadora(val) {
				documen.write(val);
		}
	function MM_jumpMenu(targ,selObj,restore){ //v3.0
	  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
	  if (restore) selObj.selectedIndex=0;
	}

	function confirmar ( mensaje ) {
					return confirm( mensaje );
				}
        </script>
</head>
<body>

<div id="background">
</div>

 
 <header>
    
    <div class="img_header_logo"></div>
    <span class="img_header_logo"><a href="http://fese.org.mx"><img src="../images/fese/FESE_home_logo.png"  height="90" alt="FESE" align="bottom" /></a></span>
    <div class="img_header_logo"></div>
    
  
<div id="menu">
<ul>
  <li class="nivel1"><a href="../private/ROV.php" class="nivel1">Inicio</a></li>
  <li class="nivel1"><a href="../report/report_rov_candidatos.php" class="nivel1">Candidatos</a></li>
 
  </li>
	
</ul>
</div><!--Menu NAV-->

</header>

<center>
<div id="boxcontainer">
<div id="container">

<h2>ASIGNACIÓN DE CANDIDATO A <?php if($_SESSION['MM_tp_programa']=="MI PRIMERA EMPRESA"){echo "PRIMARIA";}else{echo "EMPRESA";};?></h2>
<form action="<?php echo $editFormAction; ?>" method="POST" name="formRegCandidato">
<table name="t_candidato" width="720px" border="1">
	
    <tr>
		<td colspan="2"><h3>RESUMEN DE ASIGNACIÓN</h3></td>
		</tr>
    <tr>
		<td>CANDIDATO</td>
		<td><span id="nombre">
		  <input name="insNombre" type="text" id="insNombre" style="width:280px" onChange="conMayusculas(this)" readonly value="<?php if(isset($_GET['name'])){echo base64_decode($_GET['name']);}?>">
		  <span class="textfieldRequiredMsg">Se necesita un valor.</span></span></td>
	</tr>
	<tr>
	  <td><?php if($_SESSION['MM_tp_programa']=="MI PRIMERA EMPRESA"){echo "PRIMARIA";}else{echo "EMPRESA";}?></td>
	  <td><span id="direccion">
	    <input name="insDireccion" type="text" id="insDireccion" style="width:280px" onChange="conMayusculas(this)" readonly value="<?php if(isset($_GET['nomFiscal'])){echo base64_decode($_GET['nomFiscal']);}else if(isset($_GET['nomPrimaria'])){echo base64_decode($_GET['nomPrimaria']);}?>">
	    <span class="textfieldRequiredMsg">Se necesita un valor.</span></span></td>
	  </tr>
    <tr>
      <td colspan="2"><input name="ins_ies_empresa" type="hidden" id="ins_ies_empresa" value="<?php echo $row_rs_ies_empresa[0] ?>">
        <input name="ins_candidato" type="hidden" id="ins_candidato" value="<?php  echo $_GET['user']?>"></td>
    </tr>
    <tr>
		<td colspan="2" style="text-align:center;"><input type="submit" class="button" value="Guardar y Finalizar" onClick="return confirmar('¿Esta seguro que desea registrar los datos ingresados?')"></td>
		</tr>
    
</table>
<input type="hidden" name="MM_insert" value="formRegCandidato">
</form>
</div><!--Container-->
<div id="rightContainer">
    <div id="Bienvenida">
    <div id="cuadro">
    <h1>Bienvenido</h1>
    </div>
    
    <div >
    <br>
            <?php echo $_SESSION['MM_UsName'] ?><br><br>
            <?php echo $_SESSION['MM_nmb_target'] ?><br>
            <a href="<?php echo $logoutAction ?>">Salir</a>
        </div>
    </div>
    <br style="clear:both"/>
    <div id="convocatoria">
    <div id="cuadro">
    <h1>Convocatoria</h1>
    </div>
    <br>
    <?php 
    if(isset($_SESSION['MM_tp_programa'])&$_SESSION['MM_tp_programa']=="Vigentes"){
        echo "<select name=\"slConvocatoria\">
        <option selected=\"selected\">Seleccione</option>
        <option value=\"empleate\">Empleate</option>
        <option value=\"experimenta\">Experimenta</option>
        <option value=\"mpe\">Mi Primera Empresa</option>
        <option value=\"vecas_vinculacion\">Vecas Vinculación</option>
        </select>
        "	;
    }else{
    echo $_SESSION['MM_tp_programa'];}
    ?>
    
    </div>
</div><!--contenedor derecho-->


</div><!--Boxcontainer-->
  
   
</center>

</body>
</html>
<?php
//mysql_free_result($rs_ies_empresa);
?>
